
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="renderer" content="webkit" />
    <link rel="shortcut icon" href="favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="author" content="Cheney" />
    
    <title>磁盘扫描工具-MxsDoc</title>
    <link href="css/logo/logo.css" rel="stylesheet">
    <link href="css/logo/logo.css" rel="stylesheet">
    <!-- CSS: Bootstrap、font-awesome、boostrapQ、 -->
    <link href="static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="static/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="static/styles/styles.css" rel="stylesheet">
    <link href="static/highlight/styles/default.css" rel="stylesheet">
    <link href="static/highlight/styles/zenburn.css" rel="stylesheet">
    <link href="static/zTree/css/metroStyle/metroStyle.css" rel="stylesheet">
    <link href="static/nprogress/nprogress.css" rel="stylesheet">
    <link href="static/styles/kancloud.css" rel="stylesheet">
    <link href="static/bootstrapQ/qiao.css" rel="stylesheet">
    <link href="static/markdown/css/editormd.min.css" rel="stylesheet">
    <link href="static/zTree/css/metroStyle/standardStyle.css" rel="stylesheet" id="zTreeCss">
    

	<!-- FreeTeam CSS-->
	<link rel="stylesheet" href="static/freeTeam/css/resetV2.css" type="text/css" media="screen" />
	<link rel="stylesheet" href="static/freeTeam/css/boot-css/bootstrap.custom.css" type="text/css" media="screen" /> 

	<!-- context.js -->
	<link rel="stylesheet" type="text/css" href="static/ContextJS/css/demo.css">
	<link rel="stylesheet" type="text/css" href="static/ContextJS/css/context.standalone.css">

    <style type="text/css">
        .editormd-preview{
            left: 0 !important;
            right: auto !important;
        }

        .editormd .CodeMirror {
            float: right !important;
        }

        .editor-content table thead tr {
            color: #111111 !important;
        }
    </style>


    <script src="static/scripts/jquery.min.js" type="text/javascript"></script>
    <!-- Include all compiled plugins (below), or include individual file	s as needed -->
	<script type="text/javascript" src="static/bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="static/layer/layer.js"></script>
	<script type="text/javascript" src="static/nprogress/nprogress.js"></script>
	<script type="text/javascript" src="static/highlight/highlight.js"></script>
	<script type="text/javascript" src="static/highlight/highlightjs-line-numbers.min.js"></script>
	<script type="text/javascript" src="static/bootstrapQ/qiao.js"></script>
	<script type="application/javascript" src="static/markdown/lib/raphael.min.js"></script>
	<script type="application/javascript" src="static/scripts/jsonEscape.js"></script>
	<!-- zTree -->
	<script type="text/javascript" src="static/zTree/js/jquery.ztree.all.min.js"></script>
	<!-- For ajax form submit -->
	<script  type="text/javascript" src="static/scripts/jquery.form.js"></script>
	<!-- context。js -->
	<script type="text/javascript" src="static/ContextJS/js/context.js"></script>
	<!-- <script  type="text/javascript" src="static/ContextJS/js/jquery.min.js"></script>
	 -->
    <script src="js/common.js" type="text/javascript"></script>
    <script src="js/DocSys.js" type="text/javascript"></script>
</head>
<body>
<div class="m-manual manual-reader">
    <header class="navbar navbar-static-top manual-head" role="banner">
        <div class="container-fluid">
            <div class="navbar-header pull-left manual-title">
            	<a class="navbar-brand" href="/DocSystem/web/projects.html" style="margin-top:10px;">
            		<i class="logo small"></i> 
            		MxsDoc
            	</a>
            	<div class="searchbar pull-left visible-lg-inline-block visible-md-inline-block">
                    <div class="form-inline">
                		<span></span>
                        <input class="form-control" id="searchWord" name="searchWord" type="search" placeholder="请输入搜索路径..." style="width:500px;">
                    	<button id="btnLargeFileScan" class="search-btn" onclick="largeFileScan();">
                            <i class="fa fa-search"></i>
                        </button>
                    	<button id="btnFileSelector" class="btn btn-default" type="button" onclick="openFileSelector()" style="margin-left:8px;">...</button>
                    </div>
                </div>               
            </div>

            <nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
                <ul class="nav navbar-nav navbar-left">
            	</ul>
                <ul class="nav navbar-nav navbar-right">
                    <button id="btnExportLargeFileList" class="btn btn-default" type="button" onclick="exportLargeFileList()" style="display:none">导出</button>
                    <button id="btnDeleteLargeFiles" class="btn btn-default" type="button" onclick="deleteLargeFiles()" style="display:none">删除</button>
                    <button id="btnCancelDeleteLargeFiels" class="btn btn-default" type="button" onclick="cancelDeleteLargeFiels()" style="display:none">取消</button>
            	</ul>
            </nav>
        </div>      
    </header>
    <article class="container-fluid manual-body">
        <div class="manual-right" style="left:0px;overflow-y: auto;">
            <div class="manual-article">
               <div id="scanInfo" style="display:none;"></div>
               
               <div class="article-body editor-content"  id="scanResult" style="min-height: 650px; display:none;">
               		<div class="panel-body eventset-list" >	
	               		<li class="eventset-tit" style="margin-top: 0px;">
							<i class="cell select w7">
								<input class='LargeFileEnable' id='LargeFileAll' value='LargeFileAll' type='checkbox' onclick='onSelectAllFile()'/>
								选择
							</i>
							<i class="cell fileinfo w30">文件路径</i>
							<i class="cell fileinfo w10">文件大小</i>
							<i class="cell fileinfo w10">修改时间</i>
							<i class="cell operation w10">操作</i>						
						</li>
					</div>
			 		

               		<!-- 列表区域-->
			 		<div class="panel-body eventset-list" id="fileListArea">
					</div>
			 </div>
			</div>
        <div class="manual-progress"><b class="progress-bar"></b></div>
    </article>
    <div class="manual-mask"></div>
</div>

<script type="text/javascript">
	//页面加载完成处理函数    
	$(document).ready(function(){
		console.log("Page is ready");
	});
</script>

<script type="text/javascript">	    
	function cancelDeleteLargeFiels() {
    	console.log("cancelSaveShare");
        $("#btnExportLargeFileList").hide();
        $("#btnDeleteLargeFiles").hide();
        $("#btnCancelDeleteLargeFiels").hide();

        //刷新分享列表
        showLargeFileList(gLargeFileList);
    }
	
	var fileSelectorCallback =  function(node)
	{
		//update pullEntryPath
		var entryPath = node.path;
		if(entryPath == undefined || entryPath == "")
		{
			entryPath = "";
		}
		if(node.name)
		{
			entryPath += node.name;	
		}
		
		if(node.localRootPath)
		{
			entryPath = node.localRootPath + entryPath;
		}
		$("#searchWord").val(entryPath);		
	}
	
   	function openFileSelector()
   	{
   		console.log("RemoteStoragePull openFileSelector");
   		var config = {};
   		var node = {};
   		config.storageType = "disk";
   		config.localDiskPath = "";
   		config.onSelect = fileSelectorCallback;   	   		
   		showFileSelectorInBootstrapDialog(config);
   	}
   		   	
	function showFileSelectorInBootstrapDialog(config)
	{
		console.log("showFileSelectorInBootstrapDialog config:", config);

		bootstrapQ.dialog({
			id: 'fileSelector',
			url: 'fileSelector.html',
			title: '文件选择',
			msg: '页面正在加载，请稍等...',
			foot: false,
			big: false,
			callback: function(){
				FileSelector.fileSelectorPageInit(config);	//fileSlector.html 页面加载完成，此时可以通过改函数传递参数了
			},
		});
	}
	
	var gLargeFileList = [];
	var gStorageType = "disk";
	var gScanTask;
	function largeFileScan(){
	   	var pathForScan = $("#searchWord").val();
		console.log("largeFileScan() pathForScan:" + pathForScan);
		$("#scanInfo").text("开始扫描...");
		$("#scanInfo").show();
		$("#scanResult").hide();
		
		$.ajax({
	                url : "/DocSystem/Doc/startLargeFileScanTask.do",
	                type : "post",
	                dataType : "json",
	                data : {
	                    storageType : "disk",
	                	localDiskPath: pathForScan,
	                },
	                success : function (ret) {
	                    console.log("startLargeFileScanTask ret:", ret);
	                	if( "ok" == ret.status )
	                    {
	                    	gScanTask = ret.data;
	                    	startQueryLargeFileScanTask(gScanTask.id, 2000);	//2秒后开始查询
	                    }
	                    else
	                    {
	                    	showErrorMessage("扫描任务启动失败:" + ret.msgInfo);
	                    }
	                },
	                error : function () {
	    		        showErrorMessage('扫描任务启动失败：服务器异常');
	                }
	    });
	}
	
	function startQueryLargeFileScanTask(scanTaskId, delayTime)
	{
		console.log("startQueryLargeFileScanTask() scanTaskId:" + scanTaskId + " delayTime:" + delayTime);
		var nextDelayTime = delayTime; //每次增加5s
		if(nextDelayTime < 60000) //最长1分钟
		{
			nextDelayTime += 5000;
		}
		
		setTimeout(function () {
			console.log("startQueryLargeFileScanTask() timerForQueryLargeFileScanTask triggered!");
			doQueryLargeFileScanTask(scanTaskId, nextDelayTime);
		},delayTime);	//check it 2s later	
	}
	
	function doQueryLargeFileScanTask(scanTaskId, nextDelayTime)
	{
		console.log("doQueryLargeFileScanTask() scanTaskId:" + scanTaskId + " nextDelayTime:" + nextDelayTime);

		$.ajax({
            url : "/DocSystem/Doc/queryLargeFileScanTask.do",
            type : "post",
            dataType : "json",
            data : {
                taskId: scanTaskId,
            },
            success : function (ret) {
        	   console.log("doQueryLargeFileScanTask() ret:",ret);        
               if( "ok" == ret.status )
               {    
            	   var task = ret.data;
           	       if(task.status == 200)
            	   {
	           	    	$("#scanInfo").hide();
	           	    	$("#btnExportLargeFileList").hide();
	                    $("#btnDeleteLargeFiles").hide();
	                    $("#btnCancelDeleteLargeFiels").hide();
				        gLargeFileList = task.result;
	           			showLargeFileList(gLargeFileList);
           	        	return;
            	   }
           	       
           	       var info = "已扫描" + task.count + "个文件, 正在扫描 [" + task.currentScanFolder + "]...";
           	    	$("#scanInfo").text(info);
		           
		           startQueryLargeFileScanTask(scanTaskId,  nextDelayTime);
               }
               else	//后台报错
               {
            	   var info = "扫描失败:" + ret.msgInfo;
          	    	$("#scanInfo").text(info);
       	       }
            },
            error : function () {	//后台异常
         	   	var info = "扫描失败:服务器异常";
      	    	$("#scanInfo").text(info);
            }
    	});	
	}
	
	function showLargeFileList(data){
		console.log("showLargeFileList");
		console.log(data);
		
		$("#scanResult").show();
		var c = $("#fileListArea").children();
		$(c).remove();
		if(data.length==0)
		{
			$("#fileListArea").append("<p>暂无数据</p>");
		}
		
		for(var i=0;i<data.length;i++){
			var d = data[i];
			
			var opBtn2 = "";
			var LargeFileId = i;
			
			opBtn2 = "<a href='javascript:void(0)' onclick='deleteLargeFileConfirm("+LargeFileId+");' class='mybtn-primary'>删除</a>";
							
			var fileInfo = d.localRootPath + d.path + d.name;
			var latestEditTime = getDate(d.latestEditTime);
			var se = "<li value="+ i +">"
				+"	<i class='cell select w5'>"
				+"		<input class='LargeFileEnable' id='LargeFile"+i+"' value='"+LargeFileId+"' type='checkbox' onclick='onSelectFile()'/>"
				+"	</i> "
				+"	<i class='cell fileinfo w30'>"
				+"		<span class='name'>"
				+"			<a id='FileInfo"+i+"' value='"+d.name+"' href='javascript:void(0)'>"+ fileInfo + "</a>"
				+"		</span>"
				+"	</i>"
				+"	<i class='cell fileinfo w10'>"
				+"		<span class='name'>"
				+"			<a id='ExpireTime"+i+"' value='"+d.size+"' href='javascript:void(0)'>"+ d.size + "</a>"
				+"		</span>"
				+"	</i>"
				+"	<i class='cell fileinfo w10'>"
				+"		<span class='name'>"
				+"			<a id='ExpireTime"+i+"' value='"+d.latestEditTime+"' href='javascript:void(0)'>"+ latestEditTime + "</a>"
				+"		</span>"
				+"	</i>"
				+"	<i class='cell operation w10'>"
				+ 		opBtn2
				+"	</i>"
				+"</li>";
			
			$("#fileListArea").append(se);
		}
	}

	function deleteLargeFileConfirm(id)
	{
	   	console.log("deleteDocLargeFileConfirm() id:" + id);
		var docInfo = gLargeFileList[id];
		if(docInfo == undefined)
		{
			console.log("deleteDocLargeFileConfirm() docInfo is null");
			return;
		}
	   	
	   	qiao.bs.confirm({
	 	    	id: 'deleteLargeFileConfirm',
	 	        msg: "是否删除 [" + docInfo.name + "]?",
	 	        close: false,		
	 	        okbtn: "删除",
	 	        qubtn: "取消",
	 	    },function () {
	 	    	//alert("点击了确定");
	 	    	deleteLargeFile(id, docInfo);
	 	    	return true;   
	 	    },function(){
	 	    	//alert("点击了取消");
	 	    	return true;
	 	    }); 
	}
	
	function deleteLargeFile(id, docInfo)
	{	
	   	console.log("deleteLargeFile() docInfo:",  docInfo);   	
	   	$.ajax({
	            url : "/DocSystem/Doc/deleteLargeFile.do",
	            type : "post",
	            dataType : "json",
	            data : {
	                storageType: gStorageType,
	                localDiskPath: docInfo.localRootPath,
	                path : docInfo.path,
	                name : docInfo.name,
	            },
	            success : function (ret) {
	                if( "ok" == ret.status ){
	                	gLargeFileList.splice(id, 1);
	                    showLargeFileList(gLargeFileList);
                    	// 普通消息提示条
						bootstrapQ.msg({
								msg : '删除成功！',
								type : 'success',
								time : 2000,
							    });
	                }
	                else
	                {
	                	showErrorMessage("删除失败:" + ret.msgInfo);
	                }
	            },
	            error : function () {
	               showErrorMessage('删除失败:服务器异常！');
	            }
	    });
	}
</script>
</body>
</html>